package person.aoao.library.controller;


import org.springframework.web.bind.annotation.*;
import person.aoao.library.entity.UserList;
import person.aoao.library.result.ResponseData;
import person.aoao.library.service.*;

import javax.annotation.Resource;
import java.util.ArrayList;

@RestController
@RequestMapping("admin")
@CrossOrigin
public class AdminController {
    @Resource
    private TypeListService typeListService;
    @Resource
    private FloorListService floorListService;

    @Resource
    private BookListService bookListService;
    @Resource
    private SeatListService seatListService;
    @Resource
    private TypeseatListService typeseatListService;
    @Resource
    private WillListService willListService;

    @Resource
    private UserListService userListService;

    /*获取列表分页*/
    @GetMapping("getList/{module}/{num}/{page}")
    public ResponseData getList(@PathVariable String module, @PathVariable Integer num, @PathVariable Integer page){
        ResponseData data=new ResponseData();
        if(module.equals("type")){
            data=this.typeListService.getTypeList(num,page);
        }

        return  data;
    }


    /*类型搜索*/
    @PostMapping("searchTypeList/{fid}/{num}/{page}")
    public ResponseData searchList(@PathVariable Integer fid,@PathVariable Integer num, @PathVariable Integer page){
        ResponseData data=new ResponseData();
        System.out.println(fid);
        data=this.typeListService.searchTypeList(fid,num,page);
        return  data;
    }

    //密码修改
    @PostMapping("editPassword")
    public ResponseData editPasswd(@RequestBody UserList userList){
        ResponseData data=this.userListService.editPaawd(userList);
        return data;
    }

    //首页数据呈现
    @GetMapping("getHomePageData")
    public ResponseData HomeData(){
        ResponseData data=this.userListService.getHomePage();
        return  data;
    }

    //当天数据
    @GetMapping("/getToDayList/{date}")
    public ResponseData getToDayList(@PathVariable String date){
        ResponseData data=this.seatListService.getToDayList(date);
        return data;
    }

    //图书借阅排序
    @GetMapping("/getHotBooks")
    public ResponseData getHotBooks(){
        ResponseData books=this.bookListService.getHotBooks();
        return books;
    }

    @PostMapping("/getWeekDataBySeat")
    public ResponseData getWeekData(@RequestBody ArrayList<String> weeks){
        System.out.println(weeks.get(0));
        ResponseData data=this.willListService.weekData(weeks);
        return data;
    }

}
